package com.oocl.crm;

import java.util.Scanner;

public class CRM {
	public static void main(String[] args) { 
		String sdasdawd;
		
		DoubleLinkList<Person> dll= new DoubleLinkList();
		dll.addNode(new Person("08", "Mike", "male", "Shanghai", "19970701", "123456"));
		dll.addNode(new Person("03", "John", "male", "Beijing", "19960701", "123456"));
		dll.addNode(new Person("01", "Jack", "male", "Shanghai", "19950701", "123456"));
		dll.addNode(new Person("05", "Amy", "female", "Shanghai", "19930201", "123456"));
		dll.addNode(new Person("04", "Sarah", "female", "Guangdong", "19990701", "555"));
		dll.addNode(new Person("07", "Lucy", "female", "Guangdong", "19930701", "987"));
		dll.addNode(new Person("02", "Tom", "male", "Chengdu", "19970701", "555"));
		dll.addNode(new Person("06", "Lily", "female", "Kunming", "19920701", "4321"));
		dll.addNode(new Person("10", "Max", "male", "Shenzhen", "19910701", "555"));
		dll.addNode(new Person("09", "White", "male", "Kunming", "19950701", "999"));
		Scanner sc = new Scanner(System.in);
		String command;
		String[] str;
		String[] str1;
		System.out.println("Welcome to the CRM system!");
		Command.helpWithoutParameter();
		boolean flag = false;
		while(true){
			
			command=sc.nextLine();
			try {
				switch (Command.commadType(command)) {
				case "L":///////
					str =command.split(" ");
					if(str.length==1)Command.searchWithoutParameter(dll);
					else
					{
						str1=str[1].split(",");
						if(str.length==1)Command.searchWithSingleParameter(dll, command);
						else Command.searchWithParameters(dll, command);
					}
					break;
				case "A"://///////
					Command.addPerson(dll, command);
					break;
				case "D":////////
					Command.deletePersonById(dll, command);
					break;
				case "U":////////
					Command.updatePerson(dll, command);
					break;
				case "O":///////
					Command.sortAndPrint(dll);
					break;
				case "H":///////
					str =command.split(" ");
					if(str.length==1)Command.helpWithoutParameter();
					else Command.helpWithParameter(command);
					break;
				case "Q":///////
					flag=true;
					break;
				default:
					break;
				}
			} catch (Exception e) {
				System.out.println("Error command!");
				e.printStackTrace();
			}
			if(flag)break;
		}
		System.out.println("CRM system exit.");
	}
}
